//
//  SportSectionHeaderView.m
//  CoolTennisBall
//
//  Created by Coollang on 16/8/15.
//  Copyright © 2016年 CoolLang. All rights reserved.
//

#import "SportSectionHeaderView.h"
#import "SportRecordGroup.h"
#import "NSAttributedString+RichText.h"
#import "NSString+Extension.h"


@interface SportSectionHeaderView ()
// 头部view不带阴影图片
@property (weak, nonatomic) IBOutlet UIView *headView;

@property (weak, nonatomic) IBOutlet UILabel *mouthYearLabel;

@property (weak, nonatomic) IBOutlet UILabel *sportTotalTimeLabel;
@property (weak, nonatomic) IBOutlet UILabel *hitBallTotalNumLabel;
@property (weak, nonatomic) IBOutlet UIImageView *shadowImageView;

@property (weak, nonatomic) IBOutlet UIButton *coverButton;


@end
@implementation SportSectionHeaderView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    
    self.headView.layer.cornerRadius = 3;
    self.headView.layer.masksToBounds = YES;
    self.headView.layer.borderWidth = 0.5;
    self.headView.layer.borderColor = [UIColor colorWithHex:0x7a7b80 alpha:0.4].CGColor;

}



+ (instancetype)sportSectionHeaderView {
    
   return [[NSBundle mainBundle] loadNibNamed:@"SportSectionHeaderView" owner:nil options:nil].firstObject;
}

- (IBAction)coverButtonClick:(UIButton *)sender {
    
    self.groupModel.isExpandGroup = !self.groupModel.isExpandGroup;
    if (self.reloadSectionCell) {
        self.reloadSectionCell();
    }
}


- (void)setGroupModel:(SportRecordGroup *)groupModel {
    _groupModel = groupModel;
    
    UIFont *monthFont = SanFranciscoFont(36);
    UIFont *yearFont = SanFranciscoFont(16);
    UIFont *dataLagerFont = SanFranciscoFont(20);
    UIFont *dataUnitFont = [UIFont fontWithDescriptor:FontDescriptorMedium(12) size:0.0f];
    
    NSString *mouthyearString = [NSString stringWithFormat:@"%@\n%@", [groupModel monthText], [groupModel yearText]];
    
    self.mouthYearLabel.attributedText = [NSAttributedString attributedString:mouthyearString subString:@[[groupModel monthText], [groupModel yearText]] colors:@[[UIColor whiteColor], [UIColor whiteColor]] fonts:@[monthFont, yearFont]];
    
    self.sportTotalTimeLabel.text = [NSString stringHourAndMinuteWith:groupModel.totalTimeInterval];
    
    NSString *timeSubString2 = nil;
    if ([NSBundle currentLanguageIsChinese]) {
        timeSubString2 = @"小时";
        NSString *hitTotalString = [NSString stringWithFormat:@"%zd次",groupModel.amountOfCount];
        self.hitBallTotalNumLabel.attributedText = [NSAttributedString attributedString:hitTotalString subString:@[@(groupModel.amountOfCount).stringValue, @"次"] colors:@[kOrangeColor, kUnSelectedColor] fonts:@[dataLagerFont, dataUnitFont]];
    }else {
        timeSubString2 = @" h";
        
        self.hitBallTotalNumLabel.text = [NSString stringWithFormat:@"%zd",groupModel.amountOfCount];
    }
  
    NSString *timeSubString1 = [NSString stringHourAndMinuteWith:groupModel.totalTimeInterval];
    NSString *timeString = [NSString stringWithFormat:@"%@%@",timeSubString1,timeSubString2];
    
    self.sportTotalTimeLabel.attributedText = [NSAttributedString attributedString:timeString subString:@[timeSubString1, timeSubString2] colors:@[kOrangeColor, kUnSelectedColor] fonts:@[dataLagerFont, dataUnitFont]];
    
    self.shadowImageView.hidden = groupModel.isExpandGroup;
}

@end
